/**
 * 售后事件管理相关js文件
 */
/**
 * 页面初期化
 */

var eventTable; // datatble
var tblCheckOrder;
var tebType = false;
var quickSearch = ""; // 快速查询
var btnAdvSearchflg = false; // 高级查询是否点击标识
var searchCondition = {
    "queryDateType" : "",
    "queryDateStart" : "",
    "queryDateEnd" : ""
}; // 高级查询
$(document).ready(function() {
	setdaterange(moment(), moment().add('days', 7));// 默认日期
	$('#queryDate').attr("disabled",true);
	showWaitVerifyTab("a");// 列表数据请求
	getCounts();// teb数据请求
	getDictList();// 售后原因类型
	getHandlePersonList();
	//按钮控制
	setPageElementStatus("event_list_page");

});

//设置时间段控件最大宽度
function setDateWidth(){
    var inputWidth = $("#queryFactDealUser").width();
    var dateWidth = inputWidth +24;
    console.log(inputWidth);
    console.log(dateWidth);
    $("#createDate").css("max-width",dateWidth+"px");
    $("#createDate").css("overflow","hidden");
    $("#createDate").attr("title",$("#createDate").children("span").text());
    //expireDate
    $("#expireDate").css("max-width",dateWidth+"px");
    $("#expireDate").css("overflow","hidden");
    $("#expireDate").attr("title",$("#expireDate").children("span").text());
    
    $("#paidDate").css("max-width",dateWidth+"px");
    $("#paidDate").css("overflow","hidden");
    $("#paidDate").attr("title",$("#paidDate").children("span").text());
}


function initDate() {
	// 到期日期区间选择控件初始化
	$('#queryDate', $('#frmAdvSearch')).daterangepicker({
	    ranges : {
            '今天' : [ moment(), moment().add('days', 1).endOf('day')],
            '昨天' : [ moment().subtract('days', 1), moment() ],
            '过去7天' : [ moment().add('days', -7).startOf('day'), moment().add('days', -1).endOf('day') ],
            '过去30天' : [ moment().add('days', -30).endOf('day'), moment().add('days', -1).startOf('day') ],
            '本月' : [ moment().startOf('month').startOf('day'), moment().endOf('month').endOf('day') ],
            '下月' : [ moment().add('month', 1).startOf('month').startOf('day'), moment().add('month', 1).endOf('month').endOf('day') ]
        },
	    timePicker : false,
//	    timePickerIncrement : 1,
//	    timePicker24Hour : true,
	    // minDate : moment().startOf('day').format('YYYY-MM-DD HH:mm'),
	    startDate : moment().subtract('days', 29).format('YYYY-MM-DD HH:mm'),	    
	    endDate : moment().format('YYYY-MM-DD HH:mm'),
	    opens : 'right', // 日期选择框的弹出位置
	    buttonClasses : [ 'btn btn-default' ],
	    applyClass : 'btn-small btn-primary blue',
	    cancelClass : 'btn-small',
	    format : 'YYYY-MM-DD HH:mm:ss', // 控件中from和to 显示的日期格式
	    separator : ' 到 ',
	    locale : {
	        applyLabel : '确定',
	        cancelLabel : '取消',
	        fromLabel : '起始时间',
	        toLabel : '结束时间',
	        customRangeLabel : '自定义',
	        daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
	        monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
	        firstDay : 1
	    }
	}, setCreatDate);
	setCreatDate();
};
// 设置创建日期
function setCreatDate(start, end) {
	 if(!start||!end){
		 $('#queryDate span', $('#frmAdvSearch')).html("请选择日期区间");
		 $('input[name="queryDateStart"]', $('#frmAdvSearch')).val("");
		 $('input[name="queryDateEnd"]', $('#frmAdvSearch')).val("");
	    }else{
	    	$('#queryDate span', $('#frmAdvSearch')).html(start.format('YYYY-MM-DD HH:mm') + ' - ' + end.format('YYYY-MM-DD HH:mm'));
	    	$('input[name="queryDateStart"]', $('#frmAdvSearch')).val(start.format("YYYY-MM-DD HH:mm"));
	    	$('input[name="queryDateEnd"]', $('#frmAdvSearch')).val(end.format("YYYY-MM-DD HH:mm"));
	    }
	 setDateWidth();
};


// 指定处理人接口
function getHandlePersonList() {
	console.log(window.top.window.$("#projectSwitch").val());
	var askData = {
		"projectId" : window.top.window.$("#projectSwitch").val(),
	};
	$.ajax({
	    type : "GET",
	    url : "/user/userList.action?length=-1",
	    data : {
		    "formJson" : JSON.stringify(askData)
	    },
	    contentType : "application/json;charset=utf-8",
	    dataType : "json",
	    async : false,// 同步
	    success : function(data) {
		    if (data.result == "success") {
			    $("#planDealUser option").remove();
			    $("#planDealUser").append("<option value=''>请选择</option>");
			    $.each(data.data, function(n, value) {
				    $('#planDealUser').append("<option value='" + value.userId + "'>" + value.userFullname + ":" + value.userAccount + "</option>");
			    });
		    } else {
			    window.top.window.showModalAlert(data.msg);
		    }
	    },
	    error : function(XMLHttpRequest, textStatus) {
		    if (XMLHttpRequest.status == 500) {
			    var result = eval("(" + XMLHttpRequest.responseText + ")");
			    alert(result.errorObject.errorText);
		    }
	    }
	});
}
// 售后原因类型
function getDictList() {
	$.ajax({
	    type : "GET",
	    url : "/dictionary/getParamDictByCode.action",
	    data : {
		    "code" : "AFTER_SALE_TYPE"
	    },
	    contentType : "application/json;charset=utf-8",
	    dataType : "json",
	    async : false,// 同步
	    success : function(data) {
		    if (data.result == "success") {
			    $("#queryEventType option").remove();
			    $("#queryEventType").append("<option value=''>请选择</option>");
			    $("#eventType option").remove();
			    $("#eventType").append("<option value=''>请选择</option>");
			    $.each(data.data, function(n, value) {
				    $('#queryEventType').append("<option value='" + n + "'>" + value + "</option>");
				    $('#eventType').append("<option value='" + n + "'>" + value + "</option>");
			    });
		    } else {
			    window.top.window.showModalAlert(data.msg);
		    }
	    },
	    error : function(XMLHttpRequest, textStatus) {
		    if (XMLHttpRequest.status == 500) {
			    var result = eval("(" + XMLHttpRequest.responseText + ")");
			    alert(result.errorObject.errorText);
		    }
	    }
	});
}
// 初始化teb数据条数
function getCounts() {

	$.ajax({
	    type : "GET",
	    url : "/afterSale/queryStateCount.action",
	    data : {
	        "quickSearch" : quickSearch,
	        "formJson" : encodeURI(JSON.stringify(searchCondition))
	    },
	    contentType : "application/json;charset=utf-8",
	    dataType : "json",
	    async : true,// 同步
	    success : function(data) {
		    if (data.result == "success") {
			    $("#finishNum").html(data.countComplete);
			    $("#processingNum").html(data.countProcessing);
			    $("#waitingNum").html(data.countPending);
			    // $("#waitingNum3").html(data.countCancal);

		    } else {
			    window.top.window.showModalAlert(data.msg);
		    }
	    },
	    error : function(XMLHttpRequest, textStatus) {
		    if (XMLHttpRequest.status == 500) {
			    var result = eval("(" + XMLHttpRequest.responseText + ")");
			    alert(result.errorObject.errorText);
		    }
	    }
	});
//	quickSearch = "";
};

// 初始化补发单表格（默认待审核）
function showWaitVerifyTab(type) {
	// 设置列的显示隐藏
	if (type == "a") {
		tebType = false;
	} else if (type == "p") {
		tebType = true;
	} else if (type == "z") {
		tebType = true;
	}
	if(!$.fn.DataTable.isDataTable('#eventTable')){
	    
	    eventTable = $("#eventTable")
	    .DataTable({
	        "processing" : true,
	        "serverSide" : true,
	        "lengthMenu" : [  [ 10, 25, 50, 100 , 500 , 1000 ], [ 10, 25, 50, 100 , 500 , 1000 ] ],
	        "dom" : '<"bottom"rtflp>',
	        "searching" : false,
	        "scrollX" : "100%",
            "scrollXInner" : "110%",
            "scrollY" : "410px",
            "scrollCollapse": false,
	        "bPaginate" : true, // 是否显示（应用）分页器
	        "bInfo" : true, // 是否显示页脚信息，DataTables插件左下角显示记录数
	        "pagingType" : "full_numbers",
	        "deferRender" : true,
	        "ajax" : {
	            "url" : "/afterSale/getEventList.action",
	            "data" : function(d) {
	                d.quickSearch = quickSearch;
	                d.formJson = encodeURI(JSON.stringify(searchCondition));
	                d.eventStatus = type;
	            }
	        },
	        "tableTools" : {
	            "sRowSelect" : "bootstrap"
	        },
	        "columnDefs" : [{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 1 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 2 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 3 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 4 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 5 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 6 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 7 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 8 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 9 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 10 ]
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 11 ]
	        },{
                "className" : "truncate-text tooltip-column-detail",
                "targets" : [ 12 ]
            },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 13 ],
	            "visible" : false
	        },{
	        	"className" : "truncate-text tooltip-column-detail",
	            "targets" : [ 14 ]
	        },{
                "className" : "truncate-text tooltip-column-detail",
                "targets" : [ 15 ]
            },{
                "className" : "truncate-text tooltip-column-detail",
                "targets" : [ 16 ]
            },{
	        	"className" : "",
	            "targets" : [ 17 ]
	        } ],
	        "columns" : [ {
	            "data" : "sonShow",
	            "orderable" : false
	        }, {
	            "data" : "eventStatus",
	             "orderable":false,
	            "render" : function(data, type, row, meta) {
	                if (row.eventStatus == "a") {
	                    return "待处理";
	                } else if (row.eventStatus == "p") {
	                    return "处理中";
	                } else if (row.eventStatus == "z") {
	                    return "已完成";
	                }
	            }
	        }, {
	            "data" : "eventCode",
	            "orderable" : false
	        }, {
	            "data" : "orderCode",
	            "orderable" : false
	        }, {
	            "data" : "tradeCode",
	            "orderable" : false
	        }, {
	            "data" : "stockoutCode",
	            "orderable" : false
	        }, {
                "data" : "lgstNo",
                "orderable" : false
            }, {
                "data" : "shopName",
                "orderable" : false
            }, {
	            "data" : "eventType",
	            "orderable" : false
	        }, {
	            "data" : "createTime",
	        }, {
	            "data" : "expireTime"
//	            "orderable" : false
	        }, {
                "data" : "paidDate"
//              "orderable" : false
            },{
	            "data" : "buyerNick",
	            "orderable" : false
	        }, {
	            "data" : "eventCreator",
	            "orderable" : false
	        }, {
	            "data" : "planDealUserName",
	            "orderable" : false
	        }, {
	            "data" : "factDealUserName",
	            "orderable" : false//,
//	            "sClass" : "hiddenCol"
	        }, {
	            "data" : "remark",
	            "orderable" : false
	        }, {
	            "data" : "operation",
	            "orderable" : false
	        } ],
	        "order" : [ [ 9, "desc" ] ]
	        
	    })
	    .on(
	            'draw.dt',
	            function() {
	            	//解决因滚动条导致的列对不齐问题
	                $(".dataTables_scrollBody").css("overflow-y","overlay");
	                $("table").find("th.sorting_asc").removeClass("sorting_asc");
	                // 表格绘制完成后的回调事件
	                $('#eventTable td .fa-chevron-down')
	                .on(
	                        'click',
	                        function(event) {
	                            event.stopPropagation();
	                            var tr = $(this).closest("tr");
	                            row = eventTable.row(tr);
	                            
	                            if (row.child.isShown()) {
	                                row.child.hide();
	                                tr.removeClass('shown');
	                                $(this).removeClass('fa-chevron-up');
	                                $(this).addClass('fa-chevron-down');
	                            } else {
	                                // 关闭其他
	                                $('#eventTable tbody tr').each(function() {
	                                    if ($(this).attr("role") == "row") {
	                                        eventTable.row($(this)).child.hide();
	                                    }
	                                });
	                                
	                                $('.fa-chevron-up', $('#eventTable tbody')).addClass('fa-chevron-down');
	                                $('.fa-chevron-down', $('#eventTable tbody')).removeClass('fa-chevron-up');
	                                
	                                var orderId = row.data().orderId;
	                                var ifmSrc = "/views/base/note/notelist.html?busiKey=" + orderId;
	                                var temp = '<iframe myid="" tab="" shopType="" id="contentFrame1" name="contentFrame" style="width:100%;" frameborder="0" scrolling="auto" src="'
	                                    + ifmSrc + '" width="100%" height="350"></iframe>';
	                                row.child(temp).show();
	                                tr.addClass("shown");
	                                $(this).addClass('fa-chevron-up');
	                                $(this).removeClass('fa-chevron-down');
	                            }
	                            return false;
	                        });
	            });
	}else{
	    var optionData = eventTable.settings()[0].ajax.data;
	    
	    optionData = function(d){
	        d.quickSearch = quickSearch;
            d.formJson = encodeURI(JSON.stringify(searchCondition));
            d.eventStatus = type;
	    }
//	    
//        if (optionData.formJson) {
//            optionData.formJson = encodeURI(JSON.stringify($.extend(true, {}, $.parseJSON(optionData.formJson), $.parseJSON(queryData))));
//        }
////        optionData.quickSearch = quickSearch;
////        optionData.formJson = quickSearch;
//        optionData.eventStatus = type;

        eventTable.settings()[0].ajax.data = optionData;
        eventTable.ajax.reload();
	}
	
	$("#eventTable").tooltip({
        selector: ".tooltip-column-detail",
        container: "body",
        title: function() {
            if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                return $(this).text();
            }
        }
    });

};

// 重新加载dataTable的数据
function refreshWaitVerifyData(e) {
	var dttable;
//	if ($('#eventTable').hasClass('dataTable')) {
//	    if($.fn.DataTable.isDataTable('#eventTable')){
//	        dttable = $('#eventTable').DataTable();
//	        dttable.destroy();
//	    }
//	}
	showWaitVerifyTab(e);
}

/* 待处理 */
$("#waitVerifyA").on('show.bs.tab', function(e) {
	refreshWaitVerifyData("a");
	eventTable.column(12).visible(false,true).draw(true);
	eventTable.columns.adjust().draw();
});
/* 处理中 */
$("#processing").on('show.bs.tab', function(e) {
	refreshWaitVerifyData("p");
	eventTable.column(12).visible(true,true).draw(true);
	eventTable.columns.adjust().draw();
});
/* 处理完成 */
$("#finish").on('show.bs.tab', function(e) {
	refreshWaitVerifyData("z");
	eventTable.column(12).visible(true,true).draw(true);
	eventTable.columns.adjust().draw();
});

// 刷新

$("#btnRefreshEvent").on('click', function() {  
    $('#quickSearch').val("");
    quickSearch = "";
    $("#advSearchReset").click();
    searchCondition = {};
    if (!$("#advSearchPanel").is(":hidden")){
        $("#btnAdvSearch").click();   
    }  
    refresh();
})
/*
 * 快速查询
 */
$("#btnQuickSearch").click(function() {
	quickSearch = encodeURI($('#quickSearch').val());
	refresh();

});

/**
 * 搜索框的回车事件
 */ 
$('#quickSearch').keydown(function(e){
    if(e.keyCode==13 && $('#btnQuickSearch').is(":visible")){
        $("#btnQuickSearch").click();
    }
});

/*
 * 高级检索按钮点击
 */
$("#btnAdvSearch").click(function() {
	btnAdvSearchflg = true;
	if ($("#advSearchPanel").is(":hidden")) {
		$("#btnQuickSearch").hide();
        $("#advSearchPanel").show();
		$(this).children("i:eq(0)").removeClass("fa-angle-double-down");
		$(this).children("i:eq(0)").addClass("fa-angle-double-up");
	} else {
		$("#advSearchPanel").hide();
        $("#btnQuickSearch").show();
		$(this).children("i:eq(0)").removeClass("fa-angle-double-up");
		$(this).children("i:eq(0)").addClass("fa-angle-double-down");
	}
	// 初始化日期控件
	initDate();
	setCreatDate();
//	setExpireDate();
});
//$("#advSearchPanel").click(function() {
//	btnAdvSearchflg = true;
//})
//$("body .daterangepicker").click(function() {
//	btnAdvSearchflg = true;
//})
/**
 * body点击的时候高级检索收回
 */
//$(".page-content").click(function(e) {
//	if (btnAdvSearchflg == true) {
//		btnAdvSearchflg = false;
//	} else {
//		$("#advSearchPanel").hide();
//		$("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
//		$("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
//	}
//});
//时间类型为请选择时，时间不可选
$("#queryDateType").change(function(){
	if($('#queryDateType').val() == ""){
		$('#queryDateStart').val('');
		$('#queryDateEnd').val('');
		$('#queryDate').attr("disabled",true);
	}else{
		$('#queryDateStart').val('');
		$('#queryDateEnd').val('');
		$('#queryDate').attr("disabled",false);
	}
	setCreatDate();
});

// 重置按钮
$("#advSearchReset").click(function() {
	$('#queryDateType').val('');
	$('#queryDateStart').val('');
	$('#queryDateEnd').val('');
	$('#queryDate').attr("disabled",true);
//	$('#queryCreateTimeS').val('');
//	$('#queryCreateTimeE').val('');
//	$('#queryExpireTimeS').val('');
//	$('#queryExpireTimeE').val('');
//	$('#queryPaidDateS').val('');
//    $('#queryPaidDateE').val('');
	setCreatDate();
//	setExpireDate();
//	setPaidDate();
});

// 高级搜索“提交”按钮点击
$("#advSearchSubmit").click(function(e) {
	searchCondition = {
	    "queryDateType" : $('#queryDateType').val(),
	    "queryDateStart" : $('#queryDateStart').val(),
	    "queryDateEnd" : $('#queryDateEnd').val()
	};
	quickSearch = encodeURI($('#quickSearch').val());
	refresh();
//	$("#advSearchPanel").hide();
//	$("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
//	$("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
//	searchCondition = {};

});

/*
 * 刷新方法
 */
function refresh() {
	$("div .active").each(function() {
		switch ($(this).attr("id")) {
		case "waitVerifyA": // 待审核
			refreshWaitVerifyData("a");
			break;
		case "processing": // 待发货
			refreshWaitVerifyData("p");
			break;
		case "finish": // 已完成
			refreshWaitVerifyData("z");
			break;
		default:
			break;
		}
	});
	getCounts();
};

// 根据项目ID获取订单
function initOrderDataTable() {
	tblCheckOrder = $("#tblCheckOrder").DataTable({
	    "processing" : true,
	    "dom" : '<"bottom"rtflp>',
	    "searching" : false,
	    "scrollX" : "97%",
	    "scrollXInner" : "100%",
	    "scrollCollapse" : false,
	    "destroy" : true,
	    "paging" : false,
	    "deferRender" : true,
	    "tableTools" : {
		    "sRowSelect" : "bootstrap"
	    },
	    "columns" : [ {
	        "data" : "goodsCode",
	        "orderable" : false
	    }, {
	        "data" : "goodsName",
	        "orderable" : false
	    }, {
	        "data" : "skuCode",
	        "orderable" : false
	    }, {
	        "data" : "skuName",
	        "orderable" : false
	    }, {
	        "data" : "ecItemName",
	        "orderable" : false
	    }, {
	        "data" : "ecSkuCode",
	        "orderable" : false
	    } ]
	});
}

$("#btnAddEvent").on('click', function() {
	$('#eventTitle').html("新建售后事件");
	$('#hidOrderCodeEvent').val('');
	$('#hidTradeCodeEvent').val('');
	$('#hidBuyerNickEvent').val('');
	$('#hidOrderIdEvent').val('');
	var btnType = "news";
	checkAddIframe("", btnType);

});

// 新建修改iframe
function checkAddIframe(eventId, btnType) {
	var eventId = eventId;

	var iframeSrc = "./views/aftersale/event/addAfterSaleEvent.html?btnType=" + btnType + "&eventId=" + eventId;
	$("#ifmEventDetail").attr("src", iframeSrc);
	$("#btnRuleDetailSave").unbind("click").bind("click", function() {
		// 调用子页面的保存方法
		window.top.frames["ifmEventDetail"].window.saveEvent(window.top.frames["ifmEventDetail"].contentWindow);
		refresh();
	});
	var addEventDialog = window.top.window.borrowCustomModalDialog($("#eventAddWindow"));
	addEventDialog.on('hide.bs.modal', function() {
		// 父窗体归还本页的编辑对话框
		window.top.window.returnCustomModalDialog();
	});
	addEventDialog.modal({
	    show : true,
	    backdrop : 'static'
	});
}

// 关闭新增入库单页面
$('#eventAddWindow').on('hidden.bs.modal', function() {
});

// 关闭新增入库单页面
$('#eventAddWindow').on('hide.bs.modal', function() {
	window.top.window.returnCustomModalDialog();
});


// 设置时间区间，用于区间的初始化和区间控件选择后的回调
setdaterange = function(start, end) {
	$('.reportrange span', $('#frmAdvSearch')).html(start.format('YYYY-MM-DD HH:mm') + ' - ' + end.format('YYYY-MM-DD HH:mm'));
	$('input[name="queryDateStart"]', $('#frmAdvSearch')).val(start.format("YYYY-MM-DD HH:mm"));
	$('input[name="queryDateEnd"]', $('#frmAdvSearch')).val(end.format("YYYY-MM-DD HH:mm"));
}

/*
 * 处理按钮点击
 */
function disposeEvent(eventId, btnObj) {
	var currentUser = "";
	currentUser = window.top.window.$("#userName").text();
	console.log(currentUser);
	var thisTr = $("#" + btnObj.id).parents("tr");
	var planDealUser = thisTr.children('td').eq(11).text();
	console.log(planDealUser);
	if (currentUser == planDealUser) {
		getdisposeEvent(eventId)
	} else {
		window.top.window.showModalConfirm("您不是被指派的处理人员，是否继续执行操作", function() {
			getdisposeEvent(eventId)
		});
	}

}

// 处理接口请求
function getdisposeEvent(eventId) {
	var loading = window.top.window.getIndexBusyOverlay();
	var eventIds = eventId;
	$.ajax({
	    type : "GET",
	    url : "/afterSale/dealEvent.action",
	    data : {
		    "eventIds" : eventIds
	    },
	    contentType : "application/json;charset=utf-8",
	    dataType : "json",
//	    async : true,// 同步
	    beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
	    success : function(data) {
	    	loading.remove();
		    if (data.result == "success") {
			    window.top.window.showModalAlert(data.msg);
			    refresh();
		    } else {
			    window.top.window.showModalAlert(data.msg);
		    }
	    },
	    error : function(XMLHttpRequest, textStatus) {
	    	loading.remove();
		    if (XMLHttpRequest.status == 500) {
			    var result = eval("(" + XMLHttpRequest.responseText + ")");
			    alert(result.errorObject.errorText);
		    }
	    }
	});
}

/*
 * 删除按钮
 */
function deleteEvent(eventId, btnObj) {
	window.top.window.showModalConfirm("是否确认删除", function() {
		getDeleteEvent(eventId);
	});
}
function getDeleteEvent(eventId) {
	var loading = window.top.window.getIndexBusyOverlay();
	var eventIds = eventId;
	$.ajax({
	    type : "GET",
	    url : "/afterSale/deleteEvent.action",
	    data : {
		    "eventIds" : eventIds
	    },
	    contentType : "application/json;charset=utf-8",
	    dataType : "json",
//	    async : true,// 同步
	    beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
	    success : function(data) {
		    if (data.result == "success") {
		    	loading.remove();
			    window.top.window.showModalAlert(data.msg);
			    refresh();
		    } else {
			    window.top.window.showModalAlert(data.msg);
		    }
	    },
	    error : function(XMLHttpRequest, textStatus) {
	    	loading.remove();
		    if (XMLHttpRequest.status == 500) {
			    var result = eval("(" + XMLHttpRequest.responseText + ")");
			    alert(result.errorObject.errorText);
		    }
	    }
	});
}
/*
 * 修改按钮点击事件
 */
function editEvent(eventId, btnObj) {
	$('#eventTitle').html("修改售后事件");
	var btnType = "check";
	checkAddIframe(eventId, btnType);

}

/*
 * 撤销按钮点击事件
 */
function operationAnnul(btnObj) {
	//
	var eventId = $(btnObj).attr("eventid");
	var eventIds = eventId;
	var loading = window.top.window.getIndexBusyOverlay();
	$.ajax({
	    type : "GET",
	    url : "/afterSale/cancelDealEvent.action",
	    data : {
		    "eventIds" : eventIds
	    },
	    contentType : "application/json;charset=utf-8",
	    dataType : "json",
//	    async : true,// 同步
	    beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
	    success : function(data) {
	    	loading.remove();
		    if (data.result == "success") {
			    window.top.window.showModalAlert(data.msg);
			    refresh();
		    } else {
			    window.top.window.showModalAlert(data.msg);
		    }
	    },
	    error : function(XMLHttpRequest, textStatus) {
	    	loading.remove();
		    if (XMLHttpRequest.status == 500) {
			    var result = eval("(" + XMLHttpRequest.responseText + ")");
			    alert(result.errorObject.errorText);
		    }
	    }
	});
};
/*
 * 完成按钮点击事件
 */
function operationComplete(btnObj) {
	window.top.window.showModalConfirm("是否执行完成操作", function() {
		getOperationComplete(btnObj)
	});
}
function getOperationComplete(btnObj) {
	var eventId = $(btnObj).attr("eventid");
	var eventIds = eventId;
	var loading = window.top.window.getIndexBusyOverlay();
	$.ajax({
	    type : "GET",
	    url : "/afterSale/completeEvent.action",
	    data : {
		    "eventIds" : eventIds
	    },
	    contentType : "application/json;charset=utf-8",
	    dataType : "json",
//	    async : true,// 同步
	    beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
	    success : function(data) {
	    	loading.remove();
		    if (data.result == "success") {
			    window.top.window.showModalAlert(data.msg);
			    refresh();
		    } else {
			    window.top.window.showModalAlert(data.msg);
		    }
	    },
	    error : function(XMLHttpRequest, textStatus) {
	    	loading.remove();
		    if (XMLHttpRequest.status == 500) {
			    var result = eval("(" + XMLHttpRequest.responseText + ")");
			    alert(result.errorObject.errorText);
		    }
	    }
	});
}
/**
 * 通用方法
 */
// 初始化下拉控件
var initSelect = function(domElement) {
	$('.selectpicker', domElement).selectpicker();
};
// ====== 公共方法 ======
